package com.atguigu.ssyx.sys.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.sys.RegionWare;
import com.atguigu.ssyx.sys.service.RegionWareService;
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author hfj
 * @since 2024-04-19
 */
@Api(tags = "开通区域接口")
@RestController
@RequestMapping("/admin/sys/regionWare")
public class RegionWareController {

    @Autowired
    private RegionWareService regionWareService;

    /**
     *
     * @param page 当前页
     * @param limit 每页记录数
     * @param regionWareQueryVo 区域仓库实体类
     * @return 开通区域列表
     */
    @ApiOperation("开通区域列表")
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Long page, @PathVariable Long limit, RegionWareQueryVo regionWareQueryVo){

        Page<RegionWare> pageParam = new Page<>(page,limit);

        IPage<RegionWare> pageModel = regionWareService.selectPageRegionWare(pageParam,regionWareQueryVo);

        return Result.ok(pageModel);
    }


    /**
     *
     * @param regionWare 仓库地区实体
     * @return 添加开通区域
     */
    @ApiOperation("添加开通区域")
    @GetMapping("/save")
    public Result addRegionWare(@RequestBody RegionWare regionWare){

        regionWareService.saveRegionWare(regionWare);
        return Result.ok(null);
    }

    /**
     *
     * @param id 区域id
     * @return 删除开通区域
     */
    @ApiOperation("删除开通区域")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id){
        regionWareService.removeById(id);
        return Result.ok(null);
    }

    /**
     *
     * @param id 区域id
     * @param status 状态值
     * @return 取消开通区域
     */
    @ApiOperation(value = "取消开通区域")
    @PostMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,@PathVariable Integer status) {
        regionWareService.updateStatus(id, status);
        return Result.ok(null);
    }
}

